<template>
    <div>
        <base-list ref="appInfo" :condition="condition" :datas.sync="appInfo" :pageSearch="pageSearch">
            <el-form :inline="true" :model="condition" class="search-form" slot="search" label-width="80px">
                <el-row>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="应用名称">
                            <auto-search-app-info @selectName="v=>condition['search_LIKE_appName']=v" :name="condition['search_LIKE_appName']"></auto-search-app-info>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="应用类型">
                            <auto-search-dic code="app_info" @selectName="v=>condition['search_EQ_appTypeName']=v"></auto-search-dic>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="所属业务">
                            <auto-search-dic code="business_type" @selectName="v=>condition['search_EQ_appBusName']=v"></auto-search-dic>
                        </el-form-item>
                    </el-col>
                    <el-col :span="3">
                        <el-button type="primary" icon="el-icon-search" @click="loadData" class="ml-80">查 询</el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-row slot="status">
                <el-col :span="24">    
                    <el-button type="primary" plain formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)" v-if="power('WPTMGR_SYSMGR_APPINFO:ADD')">新增
                        </el-button>
                </el-col>
            </el-row>
            <el-table slot="list" :data="appInfo" border stripe max-height="500">
                <el-table-column type="index" fixed="left" label="序号" width="55"></el-table-column>
                <el-table-column prop="appNo" label="应用编号"  min-width="120"></el-table-column>
                <el-table-column prop="appName" label="应用名称"  min-width="120"></el-table-column>
                <el-table-column prop="appTypeName" label="应用类型"  min-width="120"></el-table-column>
                <el-table-column prop="appBusName" label="所属业务"  min-width="120"></el-table-column>
                <el-table-column fixed="right" align="center" label="操作"  width="140">
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="handleDialogFormOpen(true,scope.row)" v-if="power('WPTMGR_SYSMGR_APPINFO:UPD')">编辑</el-button>
                        <el-button type="text" class="danger" size="small" @click="handleRemove(scope.row)" v-if="power('WPTMGR_SYSMGR_APPINFO:DEL')">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </base-list>
        <app-info-form ref="appInfoForm" @load="loadData"></app-info-form>
    </div>
</template>

<script>
import { getAppInfo, deleteAppInfo } from "@/api/system/appInfo";
import appInfoForm from "./appInfoForm";
import autoSearchAppInfo from "@/components/autocomplete/autoSearchAppInfo";
import autoSearchDic from "@/components/autocomplete/autoSearchDic";

export default {
    name: "应用管理",
    components: { appInfoForm, autoSearchAppInfo, autoSearchDic },
    data() {
        return {
            condition: {}, // 查询条件
            appInfo: [], // table数组
            pageSearch: getAppInfo // 分页查询api接口
        };
    },
    mounted() {
        this.loadData();
    },
    methods: {
        loadData() {
            this.$refs.appInfo.loadData();
        },
        handleDialogFormOpen(bool, item) {
            if (bool) {
                let form = JSON.parse(JSON.stringify(item));
                this.$refs.appInfoForm.form = {
                    id: form.id,
                    appNo: form.appNo,
                    appName: form.appName,
                    appTypeCode: form.appTypeCode,
                    appTypeName: form.appTypeName,
                    appBusCode: form.appBusCode,
                    appBusName: form.appBusName,
                    appDesc: form.appDesc
                };
                this.$refs.appInfoForm.isEdit = true;
                this.$refs.appInfoForm.dialogForm = true;
            } else {
                this.$refs.appInfoForm.dialogForm = true;
            }
        },
        handleRemove(item) {
            this.$confirm(`是否删除该数据?`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    deleteAppInfo(item.id).then(res => {
                        this.$message({
                            type: "success",
                            message: `删除成功!`
                        });
                        this.loadData();
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        }
    }
};
</script>

<style scoped>
</style>
